"""添加用户权限字段

Revision ID: add_user_permissions_fields
Revises: 8358f5338d96
Create Date: 2025-07-20 11:25:00.000000

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'add_user_permissions_fields'
down_revision = '8358f5338d96'
branch_labels = None
depends_on = None


def upgrade():
    # 添加用户权限字段
    with op.batch_alter_table('user', schema=None) as batch_op:
        batch_op.add_column(sa.Column('role', sa.String(length=20), nullable=True, server_default='user'))
        batch_op.add_column(sa.Column('can_use_dingtalk', sa.Boolean(), nullable=True, server_default='1'))
        batch_op.add_column(sa.Column('can_use_custom_tasks', sa.Boolean(), nullable=True, server_default='1'))
        batch_op.add_column(sa.Column('can_manage_packages', sa.Boolean(), nullable=True, server_default='0'))
        batch_op.add_column(sa.Column('can_manage_users', sa.Boolean(), nullable=True, server_default='0'))


def downgrade():
    # 移除用户权限字段
    with op.batch_alter_table('user', schema=None) as batch_op:
        batch_op.drop_column('can_manage_users')
        batch_op.drop_column('can_manage_packages')
        batch_op.drop_column('can_use_custom_tasks')
        batch_op.drop_column('can_use_dingtalk')
        batch_op.drop_column('role') 